@extends('newAdmin.layout.main')

@section('content')
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">车辆管理</a>
            <a><cite>车辆审核</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ 刷新</i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form action="{{url('backstage/car')}}" class="layui-form layui-col-md12 x-so" method="get">
                <input style="width:300px" type="text" name="keywords"  placeholder="请输入车主ID/所属人/车牌号码" autocomplete="off" class="layui-input">
                <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
            </form>
        </div>
        <table class="layui-table">
            <thead>
            <tr>
                <th>ID</th>
                <th>车主ID</th>
                <th>所属人</th>
                <th>车牌号码</th>
                <th>行驶证</th>
                <th>车型</th>
                <th>车长</th>
                <th>载重</th>
                <th>车厢号码</th>
                <th>派发他人使用</th>
                <th>提交日期</th>
                <th>操作</th>
            </thead>
            <tbody>
            @foreach($cars as $car)
                <tr>
                    <td>{{$car->id}}</td>
                    <td>{{$car->user_id}}</td>
                    <td>{{$car->owner}}</td>
                    <td>{{$car->number}}</td>
                    <td><img src="{{asset('')}}/{{$car->driving_license}}" alt=""></td>
                    <td>{{$car->car_type}}</td>
                    <td>{{$car->car_length}}</td>
                    <td>{{$car->weight}}</td>
                    <td>{{$car->carriage_num}}</td>
                    <td>{{$car->is_allow}}</td>
                    <td>{{$car->created_at}}</td>
                    <td class="td-manage">
                        <a title="车辆信息" onclick="x_admin_show('车辆信息', '{{url("backstage/car/info", ['id' => $car->id])}}', 600, 700)" href="javascript:;">
                            <i class="layui-icon font-24">&#xe655;</i>
                        </a>
                        @if($car->status == 0)
                        <a title="通过" onclick="enable(this, '{{$car->id}}')" href="javascript:;">
                            <i class="layui-icon font-24">&#x1005;</i>
                        </a>
                        <a title="驳回" onclick="disable(this, '{{$car->id}}')" href="javascript:;">
                            <i class="layui-icon font-24">&#x1007;</i>
                        </a>
                        @endif
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div class="page">
            {{$cars->links()}}
        </div>
    </div>
    <script>
        /*车辆-驳回*/
        function disable(obj, id){
            layer.confirm('确认要驳回吗？',function(){
                //发异步删除数据
                $.ajax({
                    url: '{{url("backstage/car/audit")}}',
                    type: 'get',
                    dataType: 'json',
                    data: {"id": id, "status": 2},
                    success: function (result) {
                        if (result.status === 0) {
                            $(obj).parents("tr").remove();
                            layer.msg('已驳回!', {icon: 1, time: 1000});
                            location.href = '{{url("backstage/car")}}';
                            return false;
                        }
                        layer.msg(result.msg);
                        return false;
                    },
                    error: function () {
                        layer.msg('系统异常，请重试！');
                        return false;
                    }
                });
                return false;
            });
        }

        /*车辆-通过*/
        function enable(obj, id){
            layer.confirm('确认要通过吗？',function(){
                //发异步删除数据
                $.ajax({
                    url: '{{url("backstage/car/audit")}}',
                    type: 'get',
                    dataType: 'json',
                    data: {"id": id, "status": 1},
                    success: function (result) {
                        if (result.status === 0) {
                            $(obj).parents("tr").remove();
                            layer.msg('已通过!', {icon: 1, time: 1000});
                            location.href = '{{url("backstage/car")}}';
                            return false;
                        }
                        layer.msg(result.msg);
                        return false;
                    },
                    error: function () {
                        layer.msg('系统异常，请重试！');
                        return false;
                    }
                });
                return false;
            });
        }
    </script>
@endsection
